//
//  HBMyProblemCell.m
//  HuoBao
//
//  Created by chaiyanan on 15/12/15.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBMyProblemCell.h"

@interface HBMyProblemCell ()

@property (nonatomic, strong) UIImageView *arrowImageView;

@end

@implementation HBMyProblemCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
//        self.backgroundColor = [LCCommon getColor:@"37383d"];
        self.backgroundColor = [UIColor clearColor];
        
        [self createCustomView];
    }
    return self;
}

- (void)createCustomView
{
    //86*102
    
    self.subTitleLable = [self createLableWithTextColor:[LCCommon getColor:@"d2d2d2"] font:[UIFont systemFontOfSize:16.0f] text:@"好玩好赚-送体验金官方，赢了随时换钱，刺激火爆-送体验金下载，好赢就是硬道理！送体验金官方，24小时客服兑分服务，网络顶级送体验金平台" textAlignment:NSTextAlignmentLeft frame:CGRectMake(15, 15, SCREEN_WIDTH-40, 10.0f) superView:self.contentView numberOfLines:0];
    
    UIImage *image = [UIImage imageNamed:@"income_zhaiquan"];
    self.arrowImageView = [[UIImageView alloc]initWithImage:image];
    self.arrowImageView.frame = CGRectMake(SCREEN_WIDTH-15-image.size.width, (Height_HBMyMsgListCell-image.size.height)/2, image.size.width, image.size.height);
    [self.contentView addSubview:self.arrowImageView];
    
    //cccccc
    self.separatorLine = [self createSepratorLineWithFrame:CGRectMake(15, Height_HBMyMsgListCell-1-1/([UIScreen mainScreen].scale), SCREEN_WIDTH-30, 1/([UIScreen mainScreen].scale)) backgroundColor:[LCCommon getColor:@"37383d"] superView:self.contentView];
    
    [self fitSubLableSize:self.subTitleLable];
    
    
}

- (UILabel *)createLableWithTextColor:(UIColor *)color font:(UIFont *)font text:(NSString *)text textAlignment:(NSTextAlignment)textAlignment frame:(CGRect)frame superView:(UIView *)superView numberOfLines:(NSInteger)numberOfLines
{
    UILabel *lable = [[UILabel alloc]initWithFrame:frame];
    lable.textColor = color;
    lable.font = font;
    lable.text = text;
    lable.textAlignment = textAlignment;
    lable.numberOfLines = numberOfLines;
    [superView addSubview:lable];
    return lable;
}

- (UIView *)createSepratorLineWithFrame:(CGRect)frame backgroundColor:(UIColor *)bgColor superView:(UIView *)superView
{
    UIView *sepratorLine = [[UIView alloc]initWithFrame:frame];
    sepratorLine.backgroundColor = bgColor;
    [superView addSubview:sepratorLine];
    return sepratorLine;
}

- (CGSize)fitSubLableSize:(UILabel *)lable
{
    CGRect lableFrame = CGRectMake(15, 15, SCREEN_WIDTH-40, 10.0f);
    
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:lable.text];;
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle setLineSpacing:8];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, lable.text.length)];
    lable.attributedText = attributedString;
    [lable sizeToFit];
    
    CGRect lableFrameNew = lable.frame;
    lableFrameNew.origin = lableFrame.origin;
    lable.frame = lableFrameNew;
    
    LLog(@"_______%@****%@",NSStringFromCGRect(lableFrame),NSStringFromCGRect(self.subTitleLable.frame));
    
    self.separatorLine.frame = CGRectMake(15, lableFrameNew.size.height+lableFrameNew.origin.y+13-1-1/([UIScreen mainScreen].scale), SCREEN_WIDTH-30, 1/([UIScreen mainScreen].scale));
    
    self.arrowImageView.frame = CGRectMake(SCREEN_WIDTH-15-self.arrowImageView.width, (lableFrameNew.size.height+lableFrameNew.origin.y+13-1-self.arrowImageView.height)/2, self.arrowImageView.width, self.arrowImageView.height);
    
    self.bounds = CGRectMake(0, 0, SCREEN_WIDTH, lableFrameNew.origin.y+lableFrameNew.size.height+13);
    return lableFrameNew.size;
}

- (void)setSubTitle:(NSString *)subTitle
{
    self.subTitleLable.text = subTitle;
    self.subTitleLable.frame = CGRectMake(15, 15, SCREEN_WIDTH-40, 10.0f);
    [self fitSubLableSize:self.subTitleLable];
}

@end
